package com.threaddemo4;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class WhenCompleteDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> f1 = CompletableFuture.supplyAsync(()->{
            System.out.println("F1 " + Thread.currentThread().getName());
            int i = 10 / 0;
            return "F1 返回值";
        });
        //param:上一个任务执行返回结果
        //e:上一个任务执行抛出的异常 如果没有异常 则为null
        CompletableFuture whenComplete = f1.whenComplete((param,e)->{
            if(e!=null){
                System.out.println("异常信息 = " + e.getMessage());
            }else{
                System.out.println("参数 = " + param);
            }
        });

        System.out.println("f1 = " + f1.get());
        System.out.println("whenComplete = " + whenComplete.get());

    }
}
